package com.qch.demo_01;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @Author qch
 * @Date 2021/8/3
 * //用了thenrun是没有返回结果的
 */
public class CompletableFutureDemo3ThenRun {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture voidCompletableFuture = CompletableFuture.supplyAsync(() -> {
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "这是结果1";
        }).thenRun(() -> {
            try {
                Thread.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("任务执行结束之后执行的语句2");

        });
        // 阻塞等待任务执行完成
        String o = (String)voidCompletableFuture.get();
        //用了thenrun是没有返回结果的
        System.out.println(o);
        System.out.println("任务执行结束3");
    }
}
